 /**
 * @file tal_attribute_rw.h
 * @brief Common process - attribute read/write
 * @version 1.0.0
 * @date 2021-09-09
 *
 * @copyright Copyright 2018-2021 Tuya Inc. All Rights Reserved.
 *
 */
#ifndef __TAL_ATTRIBUTE_RW_H__
#define __TAL_ATTRIBUTE_RW_H__


#ifdef __cplusplus
    extern "C" {
#endif

#include "tuya_cloud_types.h"
#include "tuya_zigbee_stack.h"


/**
 * @brief write zigbee attribute
 * NOTE: only for server clusters attributes
 *
 * @param[in]   endpoint: endpoint id
 * @param[in]   cluster:  cluster id
 * @param[in]   attr_id:  attribute id
 * @param[in]   data: point to attribute data to be write
 * @param[in]   type: type of attribute
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_zg_write_attribute(UINT8_T endpoint,
                                UINT16_T cluster,
                                UINT16_T attr_id,
                                VOID_T* data,
                                ZG_ATTR_TYPE_E type);

/**
 * @brief write zigbee attribute
 * NOTE: only for server clusters attributes;
 * Note that this function triggers callbacks for tal_zg_post_write_attribute_callback and tal_zg_pre_write_attribute_callback
 *
 * @param[in]   endpoint: endpoint id
 * @param[in]   cluster:  cluster id
 * @param[in]   attr_id:  attribute id
 * @param[in]   data: point to attribute data to be write
 * @param[in]   type: type of attribute
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET  tal_zg_write_attribute_with_callback(UINT8_T endpoint,
                                UINT16_T cluster,
                                UINT16_T attr_id,
                                VOID_T* data,
                                ZG_ATTR_TYPE_E type);

/**
 * @brief read zigbee attribute
 * NOTE: only for server clusters attributes
 *
 * @param[in]   endpoint: endpoint id
 * @param[in]   cluster:  cluster id
 * @param[in]   attr_id:  attribute id
 * @param[in]   data:     point to attribute data to be read
 * @param[in]   length:   length of attribute data
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tal_zg_read_attribute(UINT8_T endpoint,
                                UINT16_T cluster,
                                UINT16_T attr_id,
                                VOID_T *data,
                                UINT8_T length);

#ifdef __cplusplus
}
#endif

#endif

